package com.spring.boot.demo.controller;

import com.spring.boot.demo.pojo.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author ZhuYouBin
 * @version 1.0.0
 * @Date: 2022/10/22 12:38
 * @Description
 */
@RestController
@RequestMapping("/api")
public class JsonController {

    @GetMapping("/json")
    public List<User> json() {
        List<User> list = this.getUserList();
        return list;
    }

    // 模拟数据
    private List<User> getUserList() {
        List<User> list = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            User user = new User();
            if (i != 1) {
                user.setUsername("test-00" + i);
                user.setCreateTime(new Date());
                user.setEnabled(true);
                user.setNum(520);
            }
            list.add(user);
        }
        return list;
    }

}
